<?php
    $page = $_GET["page"];
    $rows = $_GET["rows"];
    
    include 'db.php';
    $db = new db();
    $result = $db->query("SELECT * FROM user_message1");
    $totalPages = ceil(mysql_num_rows($result)/$rows);

    if($totalPages < $page){
        $page = 1;
    }
    $responce->page = $page;
    $responce->total = $totalPages;
    $i=0; $count=0;
    while($row = mysql_fetch_array($result)) {
        if($i >= ($page-1)*$rows && $i <= $page*$rows-1){
            $responce->rows[$count]['id']= "$count";
            $responce->rows[$count]['cell']=array($row['user'],$row['message']);
            $count++;
        }
        $i++;
    }
    $responce->records = $count;
    echo json_encode($responce);
?>